package com.zlf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zlf.dao.RoleMapper;
import com.zlf.entity.Role;
import com.zlf.entity.RoleExample;
import com.zlf.service.api.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：张利锋
 * @date ：Created in 2020/11/16 15:21
 * @description： TOOD
 * @version: 1.0
 */
@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    RoleMapper roleMapper;


    @Override
    public PageInfo<Role> getPageInfo(String keyword, Integer pageNum, Integer pageSize) {

        PageHelper.startPage(pageNum,pageSize);

        List<Role> roleList = roleMapper.selectByKeyword(keyword);

        PageInfo<Role> pageInfo = new PageInfo<>(roleList);
        return pageInfo;
    }

    @Override
    public void saveRole(Role role) {

       roleMapper.insert(role);

    }

    @Override
    public void updateRole(Role role) {
        roleMapper.updateByPrimaryKeySelective(role);
    }

    @Override
    public void removeRole(List<Integer> roleIdList) {
        RoleExample roleExample = new RoleExample();
        RoleExample.Criteria criteria = roleExample.createCriteria();
        criteria.andIdIn(roleIdList);
        roleMapper.deleteByExample(roleExample);
    }

    @Override
    public List<Role> getAssignedRole(Integer adminId) {
        List<Role> assignedRole=roleMapper.getAssignedRole(adminId);
        return assignedRole;
    }

    @Override
    public List<Role> getUnAssignedRole(Integer adminId) {
        List<Role> unAssignedRole=roleMapper.getUnAssignedRole(adminId);
        return unAssignedRole;
    }


}
